<?php
namespace admin\modue\loginajax;
use inc\BaseAjax\BaseAjax;

require('../global.php');

class loginajax extends BaseAjax
{
    /**
     * 登出函数
     * @Author : bapijun
     */
    protected function logout()
    {
        session('admin_id', NULL);
        redirect('login.php');
    }
    /**
     * 登录函数
     * @Author : bapijun
     * echo 登录的状态,如归是错误的话,添加对应的错误的返回值
     */
    protected function login()
    {
        global $db;
        $row = $db->get('tb_admin', '*', array(
            'AND' => array(
                'username' => $_POST['username'],
                'password' => \MyEncry::sha256($_POST['password'])
            )
        ));
        
        if($row){
            session('admin_id', $row['tbid']);
            $cb['info'] = '';
            $cb['status'] = 'y';
        }else{
            $cb['info'] = '用户名或密码错误';
            $cb['status'] = 'n';
        }
        echo json_encode($cb);
    }
}

$ajax = new loginajax();
$ajax->dealWithAjax();
